﻿namespace LeetCodeProject._0001_1000._001_100._31_40._035;

public class Solution
{
    public int SearchInsert(int[] nums, int target)
    {
        if (nums == null || nums.Length == 0)
            return -1;
        var low = 0;
        var high = nums.Length - 1;
        while (low <= high)
        {
            var mid = low + (high - low) / 2;
            if (nums[mid] == target)
                return mid;
            if (target < nums[mid])
                high = mid - 1;
            else
                low = mid + 1;
        }

        return low;
    }
}